const MYSQL = require("../../sql/mysql");
const MYSQLConfig = require("../../sql/database");
const SQLName = MYSQLConfig.datasheetName.user_token;
/**
 * 将指定token设为过期
 * @param {object} params
 * @param {string} params.token 需要处理的token
 * @param {string} [params.comment] 备注
 * @return {Promise<{code:number,msg:string} | {code:number,msg:string}>}
 */
module.exports = async (params={}) => {
  try {
    let { token, comment } = params; 
    comment = comment ?? "token已过期";
    await MYSQL.queryPromise(
      `UPDATE ${SQLName} SET state = 2,expired_type = '1',comment='${comment}' WHERE token = '${token}'`
    );
    return { code: 0, msg: "操作成功" };
  } catch (error) {
    throw { code: 233, msg: "操作失败,未知错误" };
  }
};
